package cn.highedu.coolsharkhub.controller;

import cn.highedu.coolsharkhub.entity.vo.CategoryManagementVO;
import cn.highedu.coolsharkhub.entity.vo.CategoryVO;
import cn.highedu.coolsharkhub.service.CategoryService;
import cn.highedu.coolsharkhub.service.exception.BlankParameterException;
import cn.highedu.coolsharkhub.service.exception.EntityNotFoundException;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类别控制器类
 */
@RestController
public class CategoryController {
    Logger logger = LoggerFactory.getLogger(CategoryController.class);
    @Autowired
    CategoryService categoryService;

    /**
     * 查询首页商品类别
     * @return 首页商品类别(Spring MVC会以JSON格式返回)
     */
    @GetMapping("/categories/homepage")
    public List<CategoryVO> findHomepageCategories() {
        logger.info("查询首页商品类别");
        return categoryService.findHomepageCategories();
    }

    /**
     * 查询后台管理页面商品类别
     * @return 管理页面商品类别(返回JSON数据)
     */
    @GetMapping("/categories/management")
    public List<CategoryManagementVO> findManagementCategories() {
        logger.info("查询后台管理页面商品类别");
        return categoryService.findManagementCategories();
    }
    /**
     * 根据商品类别id删除商品类别
     */
    @DeleteMapping("/categories/{id}")
    @ResponseStatus(HttpStatus.NO_CONTENT) // 204 没有返回结果
    public String deleteById(@PathVariable Integer id) {
        logger.info("根据商品类别id删除商品类别");
        categoryService.deleteById(id);
        return "删除成功";
    }
}
